﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using XMLSpreadGear.Core;

namespace XMLSpreadGear.Templates
{
    public class Table:BaseElement
    {
        private double? dDefaultColumnWidth;

        public double? DefaultColumnWidth
        {
            get { return dDefaultColumnWidth; }
            set { dDefaultColumnWidth = value; }
        }
        private double? dDefaultRowHeight;

        public double? DefaultRowHeight
        {
            get { return dDefaultRowHeight; }
            set { dDefaultRowHeight = value; }
        }
        private ulong? lExpandedColumnCount;

        public ulong? ExpandedColumnCount
        {
            get { return lExpandedColumnCount; }
            set { lExpandedColumnCount = value; }
        }
        private ulong? lExpandedRowCount;

        public ulong? ExpandedRowCount
        {
            get { return lExpandedRowCount; }
            set { lExpandedRowCount = value; }
        }
        private ulong? lLeftCell;

        public ulong? LeftCell
        {
            get { return lLeftCell; }
            set { lLeftCell = value; }
        }
        private string sStyleID;

        public string StyleID
        {
            get { return sStyleID; }
            set { sStyleID = value; }
        }
        private ulong? lTopCell;

        public ulong? TopCell
        {
            get { return lTopCell; }
            set { lTopCell = value; }
        }
        private bool? bFullColumns;

        public bool? FullColumns
        {
            get { return bFullColumns; }
            set { bFullColumns = value; }
        }
        private bool? bFullRows;

        public bool? FullRows
        {
            get { return bFullRows; }
            set { bFullRows = value; }
        }

        private Column cColumn;

        public Column Column
        {
            get { return cColumn; }
            set { cColumn = value; }
        }

        private Row rRow;

        public Row Row
        {
            get { return rRow; }
            set { rRow = value; }
        }


        public Table(string strLocalname)
            : base(strLocalname)
        {
        }

        public Table(string strLocalname, double defaultColumnWidth, double defaultRowHeight,
            ulong expandedColumnCount, ulong expandedRowCount, ulong leftCell,
            string styleID, ulong topCell, bool fullColumns, bool fullRows,Column column,Row row)
            : this(strLocalname)
        {
            this.dDefaultColumnWidth = defaultColumnWidth;
            this.dDefaultRowHeight = defaultRowHeight;
            this.lExpandedColumnCount = expandedColumnCount;
            this.lExpandedRowCount = expandedRowCount;
            this.lLeftCell = leftCell;
            this.sStyleID = styleID;
            this.lTopCell = topCell;
            this.bFullColumns = fullColumns;
            this.bFullRows = fullRows;
            this.cColumn = column;
            this.rRow = row;
        }

        internal protected override IDictionary<string, string> RegisterElements()
        {
            IDictionary<string, string> dic = new Dictionary<string, string>();
            if(this.Column != null)
                dic.Add("Column", this.Column.ToString());

            if(this.Row != null)
                dic.Add("Row", this.Row.ToString());

            return dic;
        }

        internal protected override IDictionary<string, string> RegisterAttributes()
        {
            IDictionary<string, string> dic = new Dictionary<string, string>();
            if(this.DefaultColumnWidth != null)
                dic.Add("DefaultColumnWidth", this.DefaultColumnWidth.ToString());

            if(this.DefaultRowHeight != null)
                dic.Add("DefaultRowHeight", this.DefaultRowHeight.ToString());

            if(this.ExpandedColumnCount != null)
                dic.Add("ExpandedColumnCount", this.ExpandedColumnCount.ToString());

            if(this.ExpandedRowCount != null)
            dic.Add("ExpandedRowCount", this.ExpandedRowCount.ToString());

            if(this.LeftCell != null)
                dic.Add("LeftCell", this.LeftCell.ToString());

            if(!string.IsNullOrEmpty(this.StyleID))
                dic.Add("StyleID", this.StyleID);

            if(this.TopCell != null)
                dic.Add("TopCell", this.TopCell.ToString());

            if(this.FullColumns != null)
                dic.Add("FullColumns", this.FullColumns.ToByte().ToString());

            if(this.FullRows != null)
                dic.Add("FullRows", this.FullRows.ToByte().ToString());

            return dic;
        }

        protected override void SetDefaults()
        {
            return;
        }

        internal override string GetAttributeNamespaceURI()
        {
            return Contstants.SpredsheetAttributeNamespace;
        }

        internal override string GetAttributeNamespace()
        {
            return Contstants.SpredsheetAttributePrefix;
        }
    }
}
